package com.kitchen.entity;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * 订单实体类
 * 体现组合关系：订单包含多个订单明细
 */
public class Order {
    private Integer orderId;
    private String orderNumber;
    private String tableNumber;
    private LocalDateTime orderTime;
    private String status;
    private BigDecimal totalAmount;
    private Integer chefId;
    private LocalDateTime completeTime;
    
    // 订单明细列表 - 使用List集合
    private List<OrderItem> items;
    
    public Order() {
        this.items = new ArrayList<>();
        this.status = "待处理";
        this.totalAmount = BigDecimal.ZERO;
    }
    
    public Order(String orderNumber, String tableNumber) {
        this();
        this.orderNumber = orderNumber;
        this.tableNumber = tableNumber;
        this.orderTime = LocalDateTime.now();
    }
    
    // 计算总金额的方法
    public void calculateTotalAmount() {
        BigDecimal total = BigDecimal.ZERO;
        if (items != null) {
            for (OrderItem item : items) {
                total = total.add(item.getPrice().multiply(new BigDecimal(item.getQuantity())));
            }
        }
        this.totalAmount = total;
    }
    
    public Integer getOrderId() {
        return orderId;
    }
    
    public void setOrderId(Integer orderId) {
        this.orderId = orderId;
    }
    
    public String getOrderNumber() {
        return orderNumber;
    }
    
    public void setOrderNumber(String orderNumber) {
        this.orderNumber = orderNumber;
    }
    
    public String getTableNumber() {
        return tableNumber;
    }
    
    public void setTableNumber(String tableNumber) {
        this.tableNumber = tableNumber;
    }
    
    public LocalDateTime getOrderTime() {
        return orderTime;
    }
    
    public void setOrderTime(LocalDateTime orderTime) {
        this.orderTime = orderTime;
    }
    
    public String getStatus() {
        return status;
    }
    
    public void setStatus(String status) {
        this.status = status;
    }
    
    public BigDecimal getTotalAmount() {
        return totalAmount;
    }
    
    public void setTotalAmount(BigDecimal totalAmount) {
        this.totalAmount = totalAmount;
    }
    
    public Integer getChefId() {
        return chefId;
    }
    
    public void setChefId(Integer chefId) {
        this.chefId = chefId;
    }
    
    public LocalDateTime getCompleteTime() {
        return completeTime;
    }
    
    public void setCompleteTime(LocalDateTime completeTime) {
        this.completeTime = completeTime;
    }
    
    public List<OrderItem> getItems() {
        return items;
    }
    
    public void setItems(List<OrderItem> items) {
        this.items = items;
    }
    
    @Override
    public String toString() {
        return "Order{" +
                "orderId=" + orderId +
                ", orderNumber='" + orderNumber + '\'' +
                ", tableNumber='" + tableNumber + '\'' +
                ", status='" + status + '\'' +
                ", totalAmount=" + totalAmount +
                ", itemsCount=" + (items != null ? items.size() : 0) +
                '}';
    }
}

